package logic

import (
	"context"
	"errors"
	"video/model/mysql"

	"video/videorpc/internal/svc"
	"video/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVideoAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoAddLogic {
	return &VideoAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 视频发布
func (l *VideoAddLogic) VideoAdd(in *videorpc.VideoAddRequest) (*videorpc.VideoAddResponse, error) {
	// todo: add your logic here and delete this line

	video := &mysql.Video{
		Title:      in.Title,
		Category:   in.Category,
		Link:       in.Link,
		CoverLink:  in.CoverLink,
		Intro:      in.Intro,
		PlayNum:    int(in.PlayNum),
		LikeNum:    int(in.LikeNum),
		CollectNum: int(in.CollectNum),
		CommentNum: int(in.CommentNum),
		Status:     int(in.Status),
		UserId:     int(in.UserId),
		TopicId:    int(in.TopicId),
	}

	err := video.VideoAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("视频发布失败")
	}

	return &videorpc.VideoAddResponse{
		VideoId: int64(video.ID),
	}, nil
}
